#ifndef AABB_H_INCLUDED
#define AABB_H_INCLUDED

namespace engine {

	namespace scene {
		
		///Axis-aligned bounding box	
		class AABB {
			private:
				slVec3 m_Min;
				slVec3 m_Max;
				
			public:
				AABB(const slVec3& min, const slVec3& max) {
					m_Min = min;
					m_Max = max;
				}
				
				AABB() {
					
				}
				
				///Builds the AABB from a list of vertices
				void resizeFromVertexList(const vector<slVec3>& vertices) {
					for (vector<slVec3>::const_iterator it = vertices.begin();
							it != vertices.end(); ++it) {
					
						//Set these to stupid values then we know we have fit to 
						//the right size
						m_Min = slVec3(100000, 100000, 100000);
						m_Max = slVec3(-100000, -100000, -100000);
						
						if ((*it).m_X < m_Min.m_X) m_Min.m_X = (*it).m_X;
						if ((*it).m_Y < m_Min.m_Y) m_Min.m_Y = (*it).m_Y;
						if ((*it).m_Z < m_Min.m_Z) m_Min.m_Z = (*it).m_Z;
						
						if ((*it).m_X > m_Max.m_X) m_Max.m_X = (*it).m_X;
						if ((*it).m_Y > m_Max.m_Y) m_Max.m_Y = (*it).m_Y;
						if ((*it).m_Z > m_Max.m_Z) m_Max.m_Z = (*it).m_Z;
					}
				}
				
				const slVec3& getMin() const { return m_Min; }
				const slVec3& getMax() const { return m_Max; }
		};
	}
}

#endif // AABB_H_INCLUDED
